
var Sync = module.exports = function (){
	this._stack = [];
	this.self = {};
}

// Sync.prototype._stack = [];

Sync.prototype.add = function (fn){
	if(typeof fn == 'function')
		this._stack.push(fn)
	return this;
}

Sync.prototype.done = function (fn){
	var idx = 0, func, self = this,
		stack = this._stack;
	next();
	function next(){
		func = stack[idx++];
		// func = stack.shift();
		if(typeof func == 'function'){
			func.call(self, next);
			return;
		}
		if(idx >= stack.length && typeof fn == 'function'){
			fn.call(self, self)
			return;
		}
		// if(stack.length < 1 && typeof fn == 'function'){
		// 	self._stack = undefined;
		// 	fn.call(self, self)
		// 	return;
		// }
	}
}